package staticmenus;

import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.ajax.AjaxRequestTarget;
import cruds.tires.TiresList;
import dynamicmenus.AccessoriesMenu;
import dynamicmenus.BrandModelMenu;
import dynamicmenus.ServicesMenu;
import dynamicmenus.TiresMenu;
import home.Home;
import panels.MyAjaxLink;
import panels.MyPanel;

@SuppressWarnings("serial")
public class StaticMenu extends MyPanel{

	public StaticMenu( Home home) {
		super("menufijo", home);
		this.add(new MyAjaxLink("brandsnmodels", new BrandModelMenu(this.getHome())));
		this.add(new MyAjaxLink("services", new ServicesMenu(this.getHome())));
		this.add(new MyAjaxLink("accessories", new AccessoriesMenu(this.getHome())));
		this.add(new MyAjaxLink("tires", new TiresMenu(this.getHome(),this.initializeLinks())));
	}

	public List<MyAjaxLink> initializeLinks() {
		List<MyAjaxLink> links = new ArrayList<MyAjaxLink>();
		List<String> marcas = this.getHome().getGeneralService().getBrandSer().getTireBrands();
		for(String marca : marcas){
			links.add(
					new MyAjaxLink("link",
							        new TiresList(this.getHome(), this.getHome().getGeneralService().getStockableSer().searchTires(marca)),
							        marca)
					);
		}
		return links;
	}

	@Override
	public void changePanel(AjaxRequestTarget target) {
		this.getHome().getStaticMenu().replaceWith(this);
		this.getHome().changePanel(target,this);
		this.getHome().setStaticMenu(this);
		//this.getHome().getStaticMenu().initializeLinks();
	}

}
